{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Printing\n",
    "\n",
    "### Printers\n",
    "\n",
    "在 SymPy 中有很多 Printers 可以用, 常用的如下: \n",
    "\n",
    "- str\n",
    "- srepr\n",
    "- ASCII pretty printer\n",
    "- Unicode pretty printer\n",
    "- LaTeX\n",
    "- MathML\n",
    "- Dot\n",
    "\n",
    "### Setting up Pretty Printing\n",
    "\n",
    "`init_printing` 函数会自动选择最适合当前使用的环境的 Printer. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "init_printing()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IPython console for SymPy 1.5.1 (Python 3.7.4-64-bit) (ground types: gmpy)\n",
      "\n",
      "These commands were executed:\n",
      ">>> from __future__ import division\n",
      ">>> from sympy import *\n",
      ">>> x, y, z, t = symbols('x y z t')\n",
      ">>> k, m, n = symbols('k m n', integer=True)\n",
      ">>> f, g, h = symbols('f g h', cls=Function)\n",
      ">>> init_printing()\n",
      "\n",
      "Documentation can be found at https://docs.sympy.org/1.5.1/\n",
      "\n"
     ]
    }
   ],
   "source": [
    "init_session()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFYAAAAzCAYAAAANb/8eAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGG0lEQVR4Ae2b7ZHbNhCGdZkrwEkqiErwRwVxOrCTCnzuIDf+dfcvc+7AdgVx0oHdwdnuIO7AGndweR8EqyEhEQRAAAoz2RmIJD7248ViF4Sks7u7u81a6Pr6+g/p+mSpvuJztpTH3PjzuQ7/svb7PUCpYfM3NZj04CFAt5LzqYesGjJWA6yMfaxyW8PoHjzWBOxPAuR9D1BqyFgUY30y+SxFvuj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xvZcFaJagN6ojQfFsNj9SHeDhEJSdnvFygN7rqjra3ASd62aS1HEoDOGLCOVU4IECB6Q2JnGxnAPG8xU/qssbyecHH9+r8NU+IQnPpI5nCMfg1z5Of7U9V+FXQK9Ux2oEcLcSo8Cqo3lrTWPhZXx1OyIUHiWLUWujB4GB17lsHogY1fl+oxMuD+RBWJsLBbZkbQkHcoseHS8pdAxc5NWUVaRgjUFzwJrxNb3IkoQlxaEdHLwME8GwbVX3c8Ca8RbEaxhnHmnbOMdTgBLP/xOgYtAksDKUrEfJPjKD8RSJL/GMEiawk8TXKT2X1k8CK8bmrTUTl+mL1+KhQ8KDzZuH9au8j+0KWsRXA4k4+0TeyxuZgcn9KONa59hVY1hV0SM89TnI2jGeNdpiHttiR2A62ypwk+fBITyU0OwRXgnTpWNiwBLz+CqmekIRT/NSNuEQsqzOVaR8iE/SEV4Kr9p9joYC70EssZZLiAmzOM7qKNnSJR3h1QYthd+Ux5rBJcamyKUPHsop11ZXPDZ7S6exFlI03BF87PXTV53mMgWsJa7s5ZlhxvCkayOQSmOsE6nxgArtV5nqmDhWXnc6GgqkxehUvJFWNmnsBEq8FcCSjvAa6R9lO+WxzZeUPMmSIqujJOSgI2X2CC+KQKPGA48dLKkmf4YL7LCTLvPeoDn6yJikI7wol0aNZ1dXV3yRxubcvbvryvLa6Pq0kcw9W8lA9oWurf8ntpfZ6waPZSnuECgDuWd5/cBzB+IN7CTJpbVteCyG4Tl/qbCfDL9bV9X/lIvA37K07FLsSB+lAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\int \\sqrt{\\frac{1}{x}}\\, dx$"
      ],
      "text/plain": [
       "⌠           \n",
       "⎮     ___   \n",
       "⎮    ╱ 1    \n",
       "⎮   ╱  ─  dx\n",
       "⎮ ╲╱   x    \n",
       "⌡           "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Integral(sqrt(1/x), x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Printing Functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Integral(sqrt(1/x), x)'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# str\n",
    "str(Integral(sqrt(1/x), x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Integral(sqrt(1/x), x)\n"
     ]
    }
   ],
   "source": [
    "print(Integral(sqrt(1/x), x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"Integral(Pow(Pow(Symbol('x'), Integer(-1)), Rational(1, 2)), Tuple(Symbol('x')))\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# srepr\n",
    "srepr(Integral(sqrt(1/x), x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'use_unicode' is an invalid keyword argument for print()",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-13-3927872c3d90>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mIntegral\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msqrt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muse_unicode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: 'use_unicode' is an invalid keyword argument for print()"
     ]
    }
   ],
   "source": [
    "pprint(Integral(sqrt(1/x), x), use_unicode=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\\int \\sqrt{\\frac{1}{x}}\\, dx\n"
     ]
    }
   ],
   "source": [
    "# LaTeX \n",
    "print(latex(Integral(sqrt(1/x), x)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# str\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
